#include "CMyLock.h"

CLock::CLock()
{
#ifndef _WIN32
	pthread_mutex_init(&m_mutex, NULL);
#else
	m_mutex = ::CreateMutex(NULL, false, NULL);
#endif
}

CLock::~CLock()
{
#ifndef _WIN32
	pthread_mutex_destroy(&m_mutex);
#else
	::CloseHandle(m_mutex);
#endif
}

void CLock::Lock() const
{
#ifndef _WIN32
	pthread_mutex_lock(&m_mutex);
#else
	DWORD dw = WaitForSingleObject(m_mutex, INFINITE);
#endif
}

void CLock::UnLock() const
{
#ifndef _WIN32
	pthread_mutex_unlock(&m_mutex);
#else
	::ReleaseMutex(m_mutex);
#endif
}

CMyLock::CMyLock(const ILock& m)
	: m_lock(m)
{
	m_lock.Lock();
}

CMyLock::~CMyLock()
{
	m_lock.UnLock();
}